from sqlalchemy import Column, String, Float, Integer, BIGINT, create_engine, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql.functions import now

import config

Base = declarative_base()


class Shop(Base):
    __tablename__ = 'shop'

    id = Column(BIGINT, primary_key=True, autoincrement=True)
    shop_id = Column(String, unique=True)
    dp_id = Column(String)
    poi_id = Column(String)
    name = Column(String)
    phone = Column(String)
    min_price = Column(Float)
    month_sale_num = Column(Integer)
    latitude = Column(Integer)
    longitude = Column(Integer)
    city_name = Column(String)
    address = Column(String)
    created_at = Column(DateTime, default=now())
    updated_at = Column(DateTime)


class Food(Base):
    __tablename__ = 'food'

    id = Column(BIGINT, primary_key=True, autoincrement=True)
    shop_id = Column(BIGINT, index=True)
    name = Column(String)
    month_saled = Column(Integer)
    price = Column(Float)
    created_at = Column(DateTime, default=now())


class Discount(Base):
    __tablename__ = 'discount'

    id = Column(BIGINT, primary_key=True, autoincrement=True)
    shop_id = Column(BIGINT, index=True)
    content = Column(String)
    created_at = Column(DateTime, default=now())


# 初始化数据库连接:
engine = create_engine(config.SQLALCHEMY_DATABASE_URI)
# 创建DBSession类型:
DBSession = sessionmaker(bind=engine)
